/*
 * Course.cpp
 *
 *  Created on: Nov 15, 2012
 *      Author: monitz
 */

#include "../include/Course.h"

int Course::cur_sem=1;
//bool Course::malag=false;

void Course::log(std::stringstream &sstm)
{
	std::ofstream fh;
		fh.open("random.log",std::ios::app);
		if(fh.is_open())
		{
		fh << sstm.str();
		}
		fh.close();

}
void Course::printStudents()
{
	std::stringstream sstrm;
	for(unsigned int i=0;i<regStudents.size();i++)
	sstrm << regStudents.at(i)->getID()  <<" is taking " << this->getName() << " from " << this->department << std::endl;
	log(sstrm);
}
std::string Course::getDep()
{
	return department;
}

Course::Course(std::string name,int grade,int semester,std::string department):name(name),semester(semester),minimum(grade),department(department),regStudents()
{

}
Course& Course::getObj()
{
	return *this;
}
void Course::teach()
{
	if(this->getSemester()<=Course::cur_sem)
	{
	std::stringstream sstrm;
	sstrm <<  "teaching " << this->getName() << "(" << regStudents.size() << " students)"<< std::endl;
	log(sstrm);

	std::vector<Student*> tmp = regStudents;
	for(unsigned int i=0;i<tmp.size();i++)
	{
		tmp.at(i)->study(getObj());

	}
	tmp.clear();
	}
}
void Course::eraseRegStudent(Student &s)
{
	for(unsigned int i=0;i<regStudents.size();i++)
	{
		if(regStudents.at(i)->getID()==s.getID())
		{

			regStudents.erase(regStudents.begin()+i);
		}
	}
}
std::string Course::getName()
{
	return name;
}
int Course::getMinimum()
{
	return minimum;
}
int Course::getSemester()
{
	return semester;
}

Course::~Course()
{
}
